/*
 * @Author: weidewei
 * @Date: 2025-05-19 09:09:42
 * @LastEditors: weidewei
 * @LastEditTime: 2025-05-21 18:25:49
 * @Description:
 * @FilePath: \v3\src\main.ts
 */
import { createApp } from "vue";
import App from "./App.vue";
import VueRouter from "./router/index";
import { createPinia } from "pinia";
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
import ElementPlus from 'element-plus'; // 根据您选择的 UI 框架调整
import 'element-plus/dist/index.css'; // 样式文件
import formCreate from '@form-create/element-ui'; // 引入 FormCreate
// @ts-expect-error
import http from "@/utils/http";
import { showToast } from "@/utils/index";
import "element-plus/dist/index.css";
import CompCodeEditor from "@/components/CompCodeEditor/index.vue";

const app = createApp(App);
const pinia = createPinia();
// 注册全局事件总线
app.config.globalProperties.$bus = {
	events: {},
	emit(event: any, ...args: any) {
		(this.events[event] || []).forEach((fn: any) => fn(...args));
	},
	on(event: any, cb: any) {
		if (!this.events[event]) this.events[event] = [];
		this.events[event].push(cb);
	},
	off(event: any, cb: any) {
		if (!this.events[event]) return;
		this.events[event] = this.events[event].filter((fn: any) => fn !== cb);
	}
};
app.config.globalProperties.$http = http;
app.config.globalProperties.$showToast = showToast;
pinia.use(piniaPluginPersistedstate);
app.use(pinia);
app.use(VueRouter);
app.use(ElementPlus); // 挂载 UI 框架
app.use(formCreate); // 挂载 FormCreate
app.component("CompCodeEditor", CompCodeEditor);
app.mount("#app");
